package com.geline.sqlbackup.config;

import com.geline.sqlbackup.service.DefaultSqlBackupLogService;
import com.geline.sqlbackup.service.ShenTongBackupService;
import com.geline.sqlbackup.service.SqlBackupLogService;
import com.geline.sqlbackup.service.SqlBackupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * 数据库表数据备份自动加载配置//@Configuration
 * @author: mengx
 * @date: 2021/10/18 17:42
 */
@EnableConfigurationProperties(value = SqlBackupProperties.class)
@Slf4j
public class SqlBackupAutoConfiguration {

    @Bean
    public SqlBackupService initSqlBackupService(SqlBackupProperties properties, SqlBackupLogService baseLogService){
        SqlBackupService service = new SqlBackupService(properties, baseLogService);
        service.start();
        return service;
    }

    @Bean
    public ShenTongBackupService initShenTongBackupService(SqlBackupProperties properties){
        return new ShenTongBackupService(properties);
    }

    @Bean
    @ConditionalOnMissingBean
    public SqlBackupLogService initSqlBackupLogService(){
        return new DefaultSqlBackupLogService();
    }


}
